<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Viral Tweet Code Generation</title>
<style>
	.box {
		width: 680px;
		background:#fff;
		
		font-family:Arial, Helvetica, sans-serif;
		font-size:10pt;
		
		margin-left:auto;
		margin-right:auto;
		margin-top:15px;
		padding:30px;
		border-top:1px solid #CCCCCC;
		border-left:1px solid #CCCCCC;
		border-right:1px solid #999999;
		border-bottom:1px solid #999999;
		
		-moz-border-radius: 8px;
		-webkit-border-radius: 8px;
	}
	.box_title {
		font-size:14pt;
		font-weight:bold;
	}
	.sub_title {
		font-size:10pt;
		font-weight:bold;
	}
	
	#frm {
		width:350px;
		text-align:left;
		padding:15px;
		border:1px dotted red;
	}
</style>

<script language="javascript">
	function getHTTPObject(){
		if (window.ActiveXObject)   
			return new ActiveXObject("Microsoft.XMLHTTP");   
		else if (window.XMLHttpRequest)        
			return new XMLHttpRequest();   
		else {      
			alert("Your browser does not support AJAX.");    
			return null;   
		}
	}
	
	function validate() {
		id_message = encodeURIComponent(document.getElementById('message').value);
		id_redirect_url = encodeURIComponent(document.getElementById('redirect_url').value);
		
		if(id_message =="" || id_redirect_url =="") {
			alert("Please fill out each field in the form to generate your viral tweets code");
		} else {
			return true;
		}
	}
	
	function generate() {
		location.href="#retweet_form";
		document.getElementById('code_section').style.display="block";
		if(validate()) {
			generateCode('generate');
		}
	}
	
	function preview() {
		
		location.href="#retweet_form";
		document.getElementById('preview_section').style.display="block";
		if(validate()) {
			generateCode('preview');
		}
	}
	
	function generateCode(todonext) {
		id_message = encodeURIComponent(document.getElementById('message').value);
		id_redirect_url = encodeURIComponent(document.getElementById('redirect_url').value);
		
		url = "gc.php?message=" + id_message + "&redirect_url=" + id_redirect_url;
		
		httpObject = getHTTPObject();   

		if (httpObject != null) {
			httpObject.open("GET", url);
			httpObject.send(null);
	        httpObject.onreadystatechange = function() {
				if (httpObject.readyState == 4){
					code = httpObject.responseText;
					if(todonext=="preview") {
						document.getElementById('preview_section_content').innerHTML = code;
					} else {
						document.getElementById('retweet_code').value = code;
					}
			    }
			};
		}
	}
	
</script>

</head>

<body bgcolor="#f1f1f1">
    <div align="center">	
	 	
		<div class="box">
		   <div class="box_title" style="margin-bottom:10px;">Fill out this form to generate your code</div>
		   
		   <div id="frm">
		   		
                Default Message site visitors will re-tweet: <br/>
				<textarea style="width:350px;" id="message"></textarea> <br/><br/>
				
				Redirect URL:<br/>
				<input type="text" style="width:350px;" id="redirect_url"/> <br/><br/>
			
				<div align="center" style="padding:15px;">
					<button style="margin:5px; width:300px;" onclick="preview();">Preview How Your Retweet Form Will Look</button>
					<button style="margin:5px; width:300px;" onclick="generate();">Generate Viral Tweet Page Code</button>
				</div>

		   </div>
		</div>
		<a name="retweet_form"></a>
		<div class="box" id="preview_section" style="display:none;">
			<div class="box_title" style="margin-bottom:10px; color:red;">Here is How Your Retweet Form Will Look</div>
			<div id="preview_section_content" align="center">
				
			</div>
		</div>
		
		<div class="box" id="code_section" style="display:none;">
			<div class="box_title" style="margin-bottom:10px;">Here is Your Retweet Code.<br/>Copy and Paste this code into a page on your website</div>
			<textarea id="retweet_code" wrap="off" style="width:550px; height:150px;"></textarea>
			<button style="margin:5px;" onclick="preview();">Preview How This Retweet Form Will Look</button>
		</div>
	</div>
</body>
